import { Component } from 'vue-facing-decorator'
import toNative from '@/utils/toNative'
import TableRender, { type TableRenderColumnTypes } from '@/render/TableRender'
import type { VxeTableDataRow } from 'vxe-table'
import type { FilterDto } from '@/render/FilterRender'
import { getKeyToEnum, InsuranceTypeEnum, OpenEnsureStatusCnEnum, ProductTypeCnEnum } from '@/const/enum'
import { UploadOutlined } from '@ant-design/icons-vue'
import type { PageDto } from '@/api/types'
import type { AnyObject } from '@/types'
import { getOpenEnsureList } from '@/api/openEnsure'

@Component
export class ClientProductView extends TableRender {

    pageTitle = '筛选'

    filterConfig() {
        return {
            companyName: {
                name: '客户名称',
                element: 'input',
            },
            insureType: {
                name: '保险产品',
                element: 'select',
                readonly: true,
                value: InsuranceTypeEnum.长期保,
                options: getKeyToEnum(InsuranceTypeEnum, false, ['长期保'])
            },
            status: {
                name: '状态',
                element: 'select',
                options: getKeyToEnum(OpenEnsureStatusCnEnum, true)
            },
            createTime: {
                name: '建档时间',
                element: 'rangePicker',
            },
        } as FilterDto
    }

    tableColumnConfigOld = () => [
        {
            field: 'companyName',
            title: '客户名称',
            params: {
                path:(row) => {
                    return `/insurance-center/client-product/${row.id}`
                },
            },
            slots: {
                default: 'toNext'
            }
        },
        {
            field: 'companyId',
            title: '客户产品Id',
        },
        {
            field: 'caseCount',
            title: '案件总数',
        },
        {
            field: 'balance',
            title: '账户余额',
        },
        // {
        //     field: 'isOpenPeriod',
        //     title: '理赔率',
        // },
        {
            field: 'insureEmployeeCount',
            title: '在保员工',
        },
        {
            field: 'status',
            title: '状态',
            formatter: ({row}) => {
                return OpenEnsureStatusCnEnum[row.status]
            }
        },
        {
            field: 'saleName',
            title: '所属销售',
        },
        {
            field: 'createTime',
            title: '建档时间',
            width: 160
        },
    ] as TableRenderColumnTypes<VxeTableDataRow>

    onGoDetail() {
        this.$router.push({
            path: '/insurance-center/client-product/200',
        })
    }

    onLoadData(pageNum: number, pageSize: number, filters: AnyObject) {
        filters.createTimeStart = filters.createTime?.[0] ?? ''
        filters.createTimeEnd = filters.createTime?.[1] ?? ''
        delete filters.createTime
        return getOpenEnsureList({
            pageNum,
            pageSize,
            ...filters
        })
    }

    renderTitleBtn() {
        return <div class="flex items-center text-black-300" onClick={() => {
            this.onGoDetail()
        }}>
            <div class="mr-4">导出账单</div>
            <UploadOutlined />
        </div>
    }

    render() {
        return <>
            {super.render()}
        </>
    }
}

export default toNative<{}, {}>(ClientProductView)